package com.example.demo.common;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-01-07
 * Time: 12:31
 */

/**
 * 统一异常处理
 */
@ControllerAdvice
@ResponseBody
public class ExcpetionAdvice {
    @ExceptionHandler(Exception.class)
    public Object exceptionError(Exception e){
        //得到抛出异常后, 进行封装后返回数据.
        return AjaxResult.fail(-1, e.getMessage());
    }
}
